<?php
namespace app\api\controller;

class BillDetail extends Permission
{
    public function getList()
    {
        $page = isset($this->input_data['page']) ? $this->input_data['page'] : 1;
        $limit = isset($this->input_data['limit']) ? $this->input_data['limit'] : 15;
        $map = [];

        if( isset($this->input_data['bill_id']) && $this->input_data['bill_id'] != '') $map['bill_id'] = $this->input_data['bill_id'];
 


        $total = db('BillDetail')->where($map)->count();
        $rows = db('BillDetail')->order('id', 'ASC')->page($page,$limit)->where($map)->select();


        $list = [];
        foreach ($rows as $v) {
            $v['amountTotal'] = formatMoneyShow(bcadd($v['amount'], $v['interest']));
            $v['amount_total'] = formatMoneyShow($v['amount_total']);
            $v['amount'] = formatMoneyShow($v['amount']);
            $v['interest'] = formatMoneyShow($v['interest']);

            $v['repayTotal'] = formatMoneyShow(bcadd($v['repay_amount'], $v['repay_interest']));
            $v['repay_total'] = formatMoneyShow($v['repay_total']);
            $v['repay_amount'] = formatMoneyShow($v['repay_amount']);
            $v['repay_interest'] = formatMoneyShow($v['repay_interest']);
            
            $list[] = $v;
        }
        
        $data = [
            'total' => $total,
            'list' => $list
        ];
        $this->resSuc($data);
    }
  

}
